<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="yongjian.drp.model.User" %>
<%@ taglib uri="/struts-tags" prefix="s" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

User user = (User)session.getAttribute("user");
if(!user.getPosition().equals("root")){
	out.write("<center><img src=../../imgs/lock.jpg /><br>");
	out.write("你无权操作</center>");
	return;
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'user_add.jsp' starting page</title>
    
    <link rel="stylesheet" type="text/css" href="js/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="js/themes/icon.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/locale/easyui-lang-zh_CN.js"></script>
    
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
		$(function(){
			  $.extend($.fn.validatebox.defaults.rules, {   	
				      minLength: {   	
				          validator: function(value, param){   	
				              return value.length >= param[0];   	
				          },   	
				          message: ''  	
				      }  ,
				      equalTo:{
				    	  validator:function(value,param){
				    		 return $(param[0]).val() == value;
				    	  },
				    	  message:''
				      }
				  }); 
			  $('#btn').click(function(){
					$('#myform').form('submit',{
							url:'user_add.action' , 
							onSubmit:function(){
								if(!$('#myform').form('validate')){
									return false ;		//当表单验证不通过的时候 必须要return false 
								}
							} ,
							success:function(result){
								var result = $.parseJSON(result);
								//验证码错误
								if(result.status == "fail"){
									document.getElementById("error").innerHTML = result.msg;								
								} else {									
									location.reload(true);
									alert("成功");
								}
							}
					});
				});
		});
	</script>

  </head>
  
  <body>
	<h2>用户注册</h2>  
	<hr>
	<center>
	  	<form id="myform" action="" method="post">
	  		<table>
	  			<tr>
	  				<td>用户名</td>
	  				<td>
	  					<input type="text" name="user.username" class="easyui-validatebox" required=true 
	  						missingMessage="用户名必填" validType="minLength[3]" invalidMessage="用户名至少3个字符"
	  						style="width:200px;">
	  				</td>
	  			</tr>
	  			<tr>
	  				<td>密码</td>
	  				<td>
	  					<input type="password" id="password" name="user.password" class="easyui-validatebox" required=true 
	  						missingMessage="密码必填" validType="minLength[5]" invalidMessage="密码至少5个字符"
	  						style="width:200px;">
	  				</td>
	  			</tr>
	  			<tr>
	  				<td>密码确认</td>
	  				<td>
	  					<input type="password" name="user.password1" class="easyui-validatebox" required=true 
	  						missingMessage="请确认密码" validType="equalTo['#password']" invalidMessage="两次密码输入不一致"
	  						style="width:200px;">
	  				</td>
	  			</tr>
	  			<tr>
	  				<td>邮箱</td>
	  				<td>
	  					<input type="text" name="user.email" class="easyui-validatebox" required=true 
	  						missingMessage="邮箱必填" validType="email" invalidMessage="邮箱格式错误"
	  						style="width:200px;">
	  				</td>
	  			</tr>
	  			<tr>
	  				<td>电话</td>
	  				<td>
	  					<input type="text" name="user.tel" class="easyui-validatebox" required=true 
	  						missingMessage="联系电话必填" style="width:200px;">
	  				</td>
	  			</tr>
	  			<tr>
	  				<td>地址</td>
	  				<td>
	  					<input type="text" name="user.address" class="easyui-validatebox" required=true 
	  						missingMessage="地址必填" style="width:200px;">
	  				</td>
	  			</tr>
	  			<tr>
	  				<td>职位</td>
	  				<td>
	  					 <select name="user.position" style="width:200px;" class="easyui-validatebox" 
	  					 		required=true missingMessage="职位必填">  
						      <option value="manager">经理</option>  					
						      <option value="recorder" selected="selected">录入员</option>  					
						      <option value="accountant">会计员</option>  											
						  </select> 
	  				</td>
	  			</tr>
	  			<tr>
			    	<td>验证码</td>
			    	<td>
				    	<input id="checkcode" type="text" name="checkcode" class="easyui-validatebox" required=true
				    		missingMessage="验证码必填" style="width:200px;"/>				
			    	</td>	
	    		</tr>
	    		<tr>
	    			<td></td>
	    			<td align="center">
	    				<img src="checkCodeImage.jsp" title="验证码,看不清楚?请点击刷新验证码" 
							onClick="this.src='checkCodeImage.jsp?t='+(new Date().getTime());">
						<font color="red"><span id="error"></span></font>
	    			</td>
	    		</tr>
	  			<tr>
	  				<td></td>
	  				<td align="center">
	  					<a id="btn" class="easyui-linkbutton">注册</a>
	  				</td>
	  			</tr>
	  		</table>	
	  	</form>	
  	</center>
  	
  </body>
</html>
